package com.bmf.admin.module.scenario.controller;


import com.bmf.admin.module.scenario.entity.Branch;
import com.bmf.admin.module.scenario.pojo.ScenarioComponents;
import com.bmf.admin.module.scenario.service.ScenarioService;
import com.bmf.core.result.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * (Scenario)表控制层
 *
 * @author makejava
 * @since 2022-11-07 11:22:56
 */
@RestController
@RequestMapping("scenario")
@Api(tags = {"想定接口"})
@AllArgsConstructor
public class ScenarioController {

    private ScenarioService scenarioService;

    private final ConcurrentMap<String, ScenarioComponents> threadSafeMap = new ConcurrentHashMap<>();

    @GetMapping("/getScenarioById/{id}")
    @ApiOperation(value = "根据id查询想定")
    public R<ScenarioComponents> getScenarioById(@PathVariable("id") String id) {
        ScenarioComponents scenarioById = scenarioService.getScenarioById(id);
        threadSafeMap.put(id, scenarioById);
        return R.success(scenarioById);
    }

    @GetMapping("/receLoadingSignal/{id}")
    @ApiOperation(value = "收到想定加载信号")
    public R<ScenarioComponents> receLoadingSignal(@PathVariable("id") String id) {
        ScenarioComponents scenarioResultVo = threadSafeMap.get(id);
        return R.success(scenarioResultVo);
    }
    @GetMapping("/scenarioStart/{id}")
    @ApiOperation(value = "想定开始")
    public R scenarioStart(@PathVariable("id") String id) {
        return R.success(scenarioService.scenarioStart(id));
    }
    @GetMapping("/scenarioPause/{id}")
    @ApiOperation(value = "想定暂停")
    public R scenarioPause(@PathVariable("id") String id) {
        return R.success(scenarioService.scenarioPause(id));
    }
    @GetMapping("/adjustScenarioStepping/{id}/{step}")
    @ApiOperation(value = "调整想定步进")
    public R adjustScenarioStepping(@PathVariable("id") String id,@PathVariable("step") String step) {
        return R.success(scenarioService.adjustScenarioStepping(id,step));
    }
    @GetMapping("/endOfScenario/{id}")
    @ApiOperation(value = "结束想定")
    public R endOfScenario(@PathVariable("id") String id) {
        return R.success(scenarioService.endOfScenario(id));
    }
    @PostMapping("/saveBreakpoint")
    @ApiOperation(value = "保存断点")
    public R saveBreakpoint(Object createVo) {
        return R.success(scenarioService.saveBreakpoint(createVo));
    }
    @GetMapping("/restoreBreakpoint/{id}/{breakpointId}")
    @ApiOperation(value = "断点恢复")
    public R restoreBreakpoint(@PathVariable("id") String id,@PathVariable("breakpointId") String breakpointId) {
        return R.success(scenarioService.restoreBreakpoint(id,breakpointId));
    }


}

